package horncomb.bpm.process.def.state;

import horncomb.bpm.BpmContextHolder;
import horncomb.bpm.process.core.EndState;
import horncomb.bpm.process.core.ExecutionContext;

/**
 * @author Daniel
 */
public class EndStateDefinition extends AbstractStateDefinition implements
		EndState {
	private static final long serialVersionUID = -2966418945361247321L;

	/**
	 * @param id
	 */
	public EndStateDefinition(String id) {
		this.setId(id);
	}

	/**
	 * {@inheritDoc}
	 */
	public boolean checkBeforEntering(ExecutionContext context) {
		return true;
	}

	/**
	 * {@inheritDoc}
	 */
	public void enter(ExecutionContext context) { // 进入结束状态
		context.getToken().setState(this);
		BpmContextHolder.getContext().getProcessManagementService().update(
				context.getToken());
	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	public int hashCode() {
		return this.getClass().hashCode();
	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	public boolean equals(Object obj) {
		return obj instanceof EndState;
	}
}
